package chixing.day11.work.w10;
// 定价上下文类
public class PricingContext {
    private PricingStrategy strategy;

    public void setStrategy(PricingStrategy strategy) {
        this.strategy = strategy;
    }

    public double calculateFinalPrice(Product product) {
        if (strategy == null) {
            throw new IllegalStateException("未设置定价策略");
        }
        return strategy.calculate(product);
    }

    public String getStrategyName() {
        return strategy.toString();
    }
}

